<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	//depricated
	function final_content_data($allposts)
	{
		
	  $strr="";
	  $CI =& get_instance();		
	  
	 	
		
	  if($CI->session->userdata('GuestView')==1)  
	  {
	   	    // check for post function
		  if($CI->uri->segment(2)=="post")
		  {
			//print_r($allposts);
			$strr.='<h2>'.$allposts[0]['title_link'].'</h2>
					<p class="post-info">Posted by '.$allposts[0]['author_name'].' | Filed under '.$allposts[0]['categories'] .'</p>
					<p>'.$allposts[0]['content'].'</p>
					<p>'.$allposts[0]['read_comments'].'</p>
					<p>'.$allposts[0]['comment_form'].'</p>';
	
	echo $strr;							   
			return;
		  }
		  
	  	if($CI->uri->segment(1)=="users"||$CI->uri->segment(2)=="search"||$CI->uri->segment(2)=="do_search")
		   {
			   return $allposts;
		   }
		   
		   for($i=0;$i<count($allposts)-1;$i++)	   
		   {
		   		if($allposts[$i]['error']==TRUE)
				{	echo $allposts[$i]['description']; }
				else
				{
					if($CI->uri->segment(2)!="page" && $CI->uri->segment(1)!="users") 
					{	
						$strr.='<h2>'.$allposts[$i]['title_link'].'</h2>
								<p class="post-info">Posted by '.$allposts[$i]['author_name'].' | Filed under '.$allposts[$i]['categories'] .'</p>';
				    }
				
					if($CI->uri->segment(1)!="users")
					$strr.='<p>'.$allposts[$i]['content'].'</p>';
							
				   if($CI->uri->segment(2)!="page" && $CI->uri->segment(1)!="users") 
				   {		
						$comments=base_url().'blog/post/'.url_title($allposts[$i]['post_title']).'#comments';		
						$strr.='<p class="post-footer">		
							<a href="'.$comments.'" class="comments">Comments : '.$allposts[$i]['comment_no'].'</a> |
							<span class="date">'.$allposts[$i]['date'].'</span>	
						</p>';
                                
                                
					    if($allposts[0]['full'])
						{
							//$strr.=$allposts['read_comments'].'<p>&nbsp;</p>';
							//$strr.=$allposts['comment_form'];
						}
							  
					  } //end of comment if
				}//error if	 
			} //end of for loop
					
					$strr.=$allposts['last'];
		  } //end of user login session.
		 
          else
		  	 $strr.= "Please login! This is for members only site";
			 
		return $strr;			  
	
	}
	
	function final_sidebar_data()
	{
		$CI =& get_instance();		
		$side_array=get_data();	
		
		$side_blog['calendar']="";
		$side_blog['categories']="";
		$side_blog['latest_posts']="";
		$side_blog['latestcomment']="";
		$side_blog['archives']="";
		
		$side_blog['search_form']='<h3>Search</h3>'.
				      $side_array['SearchForm'];

			
		if($CI->session->userdata('ShowCategories')==1) 
        {
            $side_blog['categories']='<h3>Categories</h3>'.
								$side_array['Categories'];
        }
				
		if($CI->session->userdata('ShowRecentPosts')==1) 
		{
           $side_blog['latest_posts']= '<h3>Latest Entries</h3>'.
            	$side_array['RecentPosts'];
		}
                            
         if($CI->session->userdata('ShowRecentComments')==1) 
		 {
             $side_blog['latestcomment']='<h3>Latest  Comments</h3>'.
             $side_array['RecentComments'];
         }

	     if($CI->session->userdata('ShowArchives')==1) 
		 {
		    $side_blog['archives']= '<h3>Archives</h3>'.
           			 $side_array['Archives'];
         }
            
          
          if($CI->session->userdata('logged_in'))  
		  {
             $side_blog['users']= '<h3>Users</h3><ul class="sidemenu">
                           <li>Welcome '.$CI->session->userdata('first_name').'&nbsp;'.$CI->session->userdata('last_name').'</li>
                           <li>'.anchor('users/ViewProfile/'.$CI->session->userdata('user_id'),'View Profile').'</li>
                           <li>'.anchor('users/Logout','Logout').'</li>
          </ul>'; 
          } 
		  else 
		  {
               $side_blog['users']= '<h3>Users</h3><ul class="sidemenu">
                            <li>'.anchor('users/Register','Register').'</li>
                            <li>'.anchor('login/MemberLogin','Login').'</li>
                            <li>'.anchor('users/ForgetPassword','Forget Password').'</li>
                        </ul>';
           }
                       		 
                          
          $side_blog['tag_clouds']='<h3>TagClouds</h3>
           <div class="tag-cloud"> '.$side_array['TagClouds'].'</div>';
                            
          if($CI->session->userdata('ShowCalendar')==1) 
		  { 
              $side_blog['calendar']= '<h3>Calendar</h3>
                   <div  align="center"> '.$CI->calendar->generate().'</div>';
          }
		  
		  $side_blog['pages']= $side_array['pages'];
		  return $side_blog;
	}
	function get_data()
	{
		$CI =& get_instance();	
		
		$data['title']="Blogmer";
		$data['SearchForm']=$CI->load->view('required/search_form',$data,TRUE);
		$data['pages']=$CI->Main_model->PageLinks();
		$data['Categories']=$CI->Sidebar_model->categories_list();
		$data['TagClouds']=$CI->Tagclouds_model->tag_clouds(); 
		$data['RecentPosts']=$CI->Sidebar_model->recent_posts(10);
		$data['RecentComments']=$CI->Sidebar_model->recent_comments(10);
		$data['Archives']=$CI->Sidebar_model->archives_list();	
		
		return $data;
	}
	
	function get_post($id)
	{
		
		
		$CI =& get_instance();		
		$data=final_sidebar_data();
		
		$rules['name'] = "required";
		$rules['email'] = "required|trim|valid_email";
		$rules['commentbox'] = "required";
		$CI->validation->set_rules($rules);

		$fields['name'] = "Name";
		$fields['email'] = "Email ID";
		$fields['guesturl'] = "URL";
		$fields['commentbox'] = "Comment Text";
		$CI->validation->set_fields($fields);
        
		if ($CI->validation->run()) 
		{     	
			$CI->Comments_model->SaveComment();        
		} 
		else 
		{
            //load the form again with previous value
			
			$r=$CI->Main_model->SinglePostView($id,true,$id,true);
			$r['read_comments']=$CI->Comments_model->ReadComments($CI->uri->segment(3));
				  
			 
			 if($CI->session->userdata('EnableComments')=='1')
			 {
				if($CI->session->userdata('logged_in')==TRUE) //member
				{ 
					if($CI->session->userdata($CI->uri->segment(3))=='1')
						$post_str=$CI->load->view('users/comment_add',$data,TRUE);	
					else
						$post_str="<h2>Comments are closed for this post</h2>&nbsp;";
				}
				else //guest
				{
					if($CI->session->userdata('EnableGuestComment')==1) //guest global comment settings
						$post_str=$CI->load->view('users/comment_add',$data,TRUE);	
					else
						$post_str="<h3>Please Login to post a comment.</h3>&nbsp;";
				}		
					
			 }
			 else
				$post_str="<h2>Global Comments are closed.</h2>&nbsp;";
					
	
			 $r['comment_form']=$post_str;
			 $r['last']="";
			 $data['post']=$r;			
			
        }
		//print_r($data);
		return $data;
		
	}
	
	function do_search()
	{
		$CI =& get_instance();	
		$data=final_sidebar_data();
		$rules['blog_search'] = "required";
		$CI->validation->set_rules($rules);

		$fields['blog_search'] = "Search";
		$CI->validation->set_fields($fields);
        
		if ($CI->validation->run()) 
		{     	
			$CI->load->helper('search');
			$keyword=remove_special_characters($CI->input->post('blog_search'));
			$place=$CI->input->post('search_area');
						
			$data['title']="Information Page";
			$data['header']="Information";
			$data['url']='/blog/search/'.$place.'/'.$keyword;
			$data['time']="2";
			$data['message']="<p>Thank You!</p>
							  <p>Stand by while we direct you to your search results</p>
							  <p>".anchor('/blog/search/'.$place.'/'.$keyword,"Click here")."if you are not redirected automatically</p>";
			$CI->load->view('info',$data);
		} 
		else 
		{
			$data['content']=$CI->load->view('required/full_search_form',$data,TRUE);
			return $data;
        }
	}
	
	